package com.asohofrucol.dto.util;

import com.asohofrucol.dto.AgrarianResourceRegisterDTO;
import com.asohofrucol.model.AgrarianResource;
import com.asohofrucol.model.ComboValue;
import com.asohofrucol.model.Ruat;

public class AgrarianResourceHelperDto {

	public static AgrarianResourceRegisterDTO convertToRegisterDTO(
			AgrarianResource ag) {
		AgrarianResourceRegisterDTO agDTO = new AgrarianResourceRegisterDTO();
		agDTO.setHarvestedArea(ag.getHarvestedArea());
		agDTO.setAssistanceEntity(ag.getAssistanceEntity());
		agDTO.setAssistanceProgram(ag.getAssistanceProgram());
		agDTO.setCertifiedSeed((ag.getComboValueCertifiedSeed() != null) ? ag
				.getComboValueCertifiedSeed().getId() : null);

		agDTO.setCertifiedSeedDesc((ag.getComboValueCertifiedSeed() != null) ? ag
				.getComboValueCertifiedSeed().getDescription() : null);

		agDTO.setEstablishmentCosts(ag.getEstablishmentCosts());
		agDTO.setId(ag.getId());
		agDTO.setMembershipTechnicalAssistancePrograms((ag
				.getComboValueMembershipTechnicalAssistancePrograms() != null) ? ag
				.getComboValueMembershipTechnicalAssistancePrograms().getId()
				: 2L);

		// agDTO.setMembershipTechnicalAssistanceProgramsDesc((ag.getComboValueMembershipTechnicalAssistancePrograms()!=null)?ag.getComboValueMembershipTechnicalAssistancePrograms().getDescription():2L);

		agDTO.setMembershipTechnicalAssistanceProgramsDesc(ag
				.getComboValueMembershipTechnicalAssistancePrograms()
				.getDescription());

		agDTO.setMethodOfPayment((ag.getComboValueMethodOfPayment() != null) ? ag
				.getComboValueMethodOfPayment().getId() : null);

		agDTO.setMethodOfPaymentDesc((ag.getComboValueMethodOfPayment() != null) ? ag
				.getComboValueMethodOfPayment().getDescription() : null);

		agDTO.setModifiedDate(ag.getModifiedDate());
		agDTO.setModifierUser(ag.getModifierUser());
		agDTO.setProduct((ag.getComboValueProduct() != null) ? ag
				.getComboValueProduct().getId() : null);

		agDTO.setProductDesc((ag.getComboValueProduct() != null) ? ag
				.getComboValueProduct().getDescription() : null);

		agDTO.setProductionForTheMarket(ag.getProductionForTheMarket());
		agDTO.setProductOther(ag.getProductOther());
		agDTO.setRuatId(ag.getRuat().getId());
		agDTO.setSalesPriceAverage(ag.getSalesPriceAverage());
		agDTO.setSaleType((ag.getComboValueSaleType() != null) ? ag
				.getComboValueSaleType().getId() : null);

		agDTO.setSaleTypeDesc((ag.getComboValueSaleType() != null) ? ag
				.getComboValueSaleType().getDescription() : null);

		agDTO.setSellsToNameAndSurname(ag.getSellsToNameAndSurname());
		agDTO.setSemesterA(ag.getSemesterA());
		agDTO.setSemesterB(ag.getSemesterB());
		agDTO.setSiteForSale((ag.getComboValueSiteForSale() != null) ? ag
				.getComboValueSiteForSale().getId() : null);

		agDTO.setSiteForSaleDesc((ag.getComboValueSiteForSale() != null) ? ag
				.getComboValueSiteForSale().getDescription() : null);

		agDTO.setStatus(ag.getStatus());
		agDTO.setSubProduct(ag.getSubProduct());
		agDTO.setSubProductUse(ag.getSubProductUse());
		agDTO.setSustainingCosts(ag.getSustainingCosts());
		agDTO.setVariety(ag.getVariety());

		agDTO.setProductDesc(ag.getComboValueProduct().getDescription());

		return agDTO;
	}

	public static AgrarianResource converRegisterToEntity(
			AgrarianResourceRegisterDTO agDTO) {
		AgrarianResource ag = new AgrarianResource();
		ag.setHarvestedArea(agDTO.getHarvestedArea());
		ag.setAssistanceEntity(agDTO.getAssistanceEntity());
		ag.setAssistanceProgram(agDTO.getAssistanceProgram());
		ag.setComboValueCertifiedSeed(new ComboValue(agDTO.getCertifiedSeed()));
		ag.setComboValueMembershipTechnicalAssistancePrograms(new ComboValue(
				agDTO.getMembershipTechnicalAssistancePrograms()));
		ag.setComboValueMethodOfPayment(new ComboValue(agDTO
				.getMethodOfPayment()));
		ag.setComboValueProduct(new ComboValue(agDTO.getProduct()));
		ag.setComboValueSaleType(new ComboValue(agDTO.getSaleType()));
		ag.setEstablishmentCosts(agDTO.getEstablishmentCosts());
		ag.setId(agDTO.getId());
		ag.setModifiedDate(agDTO.getModifiedDate());
		ag.setModifierUser(agDTO.getModifierUser());
		ag.setProductionForTheMarket(agDTO.getProductionForTheMarket());
		ag.setProductOther(agDTO.getProductOther());
		ag.setRuat(new Ruat(agDTO.getRuatId()));
		ag.setSalesPriceAverage(agDTO.getSalesPriceAverage());
		ag.setSellsToNameAndSurname(agDTO.getSellsToNameAndSurname());
		ag.setSemesterA(agDTO.getSemesterA());
		ag.setSemesterB(agDTO.getSemesterB());
		ag.setComboValueSiteForSale(new ComboValue(agDTO.getSiteForSale()));
		ag.setStatus(agDTO.getStatus());
		ag.setSubProduct(agDTO.getSubProduct());
		ag.setSubProductUse(agDTO.getSubProductUse());
		ag.setSustainingCosts(agDTO.getSustainingCosts());
		ag.setVariety(agDTO.getVariety());
		return ag;
	}

}
